<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
      <#include "/common/elibs.html">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
  </head><body>
    <div class="x-body">
        <form class="layui-form">
            <div class="layui-form-item">
                <input type="hidden" id="userBaseInfoId" name="userBaseInfoId" lay-verify="required" value="${id}" >
                <label for="userName" class="layui-form-label">
                    <span class="x-red">*</span>姓名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="nickName" name="nickName" lay-verify="required" placeholder="请输入"
                           autocomplete="off" class="layui-input" >
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div><div class="layui-form-item">
                <label for="userName" class="layui-form-label">
                    <span class="x-red">*</span>登录名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="userName" name="userName" lay-verify="required" placeholder="请输入"
                           autocomplete="off" class="layui-input" >
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div><div class="layui-form-item">
                <label for="userPhone" class="layui-form-label">
                    <span class="x-red">*</span>用户年龄
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="userAge" name="userAge" lay-verify="number" placeholder="请输入"
                           autocomplete="off" class="layui-input" >
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div><div class="layui-form-item">
                <label for="userPhone" class="layui-form-label">
                    <span class="x-red">*</span>用户电话
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="userPhone" name="userPhone" lay-verify="phone" placeholder="请输入"
                           autocomplete="off" class="layui-input" >
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>
            <div class="layui-form-item" >
                <label for="status" class="layui-form-label">
                    <span class="x-red">*</span>用户状态
                </label>
                <div class="layui-input-inline">
                    <select  lay-filter="tcaParentsId" id="status" name="status" value="" lay-verify="required">
                        <option >请选择</option>
                        <option value="0">停用</option>
                        <option value="1">启用</option>
                        <option value="2">出现违规情况而被停用</option>
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>
            <div class="layui-form-item" >
                <label for="status" class="layui-form-label">
                    <span class="x-red">*</span>用户状态
                </label>
                <div class="layui-input-inline">
                    <select lay-filter="tcaParentsId" id="userRoleId" name="userRoleId" value="" lay-verify="required">
                        <option >请选择</option>
                        <option value="1">管理员</option>
                        <option value="2">成员</option>
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>
            <div class="layui-form-item">
              <label for="userName" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">
                  提交
              </button>
          </div>
      </form>
    </div>
    <script>
        ajaxFun('get','/pc/role/getRoleInfoList',null,function(data){
            if(data.code != 0){
                alertFun(data);
            }else{
                var html = "<option >请选择</option>";
                $("#userRoleId").html("");
                for(var i=0;i<data.data.length;i++){
                    html += "<option value='"+data.data[i].idUserRole+"'>"+data.data[i].roleName+"</option>";
                }
                $("#userRoleId").append(html);
                form.render();
            }
        })
        var params1 =  {"userBaseInfoId":$("#userBaseInfoId").val()}
            ajaxFun('get','/pc/user/getUserInfo',params1,function(data){
                if(data.code != 0){
                    alertFun(data);
                }else{
                    $("#nickName").val(data.data.nickName);
                    $("#userPhone").val(data.data.userPhone);
                    $("#userName").val(data.data.userName);
                    $("#userAge").val(data.data.userAge);
                    $("#status").val(data.data.status);
                    $("#userRoleId").val(data.data.userRoleId);
                    renderForm();
                }
            })

        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
            form.verify({
                nickName: function(value){
                    if(value.length < 0){
                        return '用户名不能为空';
                    }
                },
                userName: function(value){
                    if(value.length < 0){
                        return '姓名不能为空';
                    }
                },
                userAge: function(value){
                    if(value.length < 0){
                        return '年龄不能为空';
                    }
                },
                userPhone: function(value){
                    if(value.length < 0){
                        return '手机号不能为空';
                    }
                },
                status: function(value){
                    if(value.length < 0){
                        return '用户状态不能为空';
                    }
                },
                userRoleId: function(value){
                    if(value.length < 0){
                        return '用户类型不能为空';
                    }
                },
//            ,pass: [/(.+){6,12}$/, '密码必须6到12位']
                /*,repass: function(value){
                    if($('#L_pass').val()!=$('#L_repass').val()){
                        return '两次密码不一致';
                    }
                }*/
            });
            //监听级别
            form.on('select(status)', function(data){
                var value = data.value;
                $("#status").val(value);
            });

            //监听级别
            form.on('select(userRoleId)', function(data){
                var value = data.value;
                $("#userRoleId").val(value);
            });

          //监听提交
          form.on('submit(add)', function(t){
              if($('#newPassword1').val()!=$('#newPassword').val()){
                  layer.open({
                      title: '提示信息'
                      ,content: "两次密码不一致"
                  });
                  return false;
              }
            var params = {

                "userBaseInfoId" : $("#userBaseInfoId").val(),
                "nickName" : $("#nickName").val(),
                "userName" : $("#userName").val(),
                "userAge" : $("#userAge").val(),
                "userPhone" : $("#userPhone").val(),
                "status" : $("#status").val(),
                "userRoleId" : $("#userRoleId").val()
              }
            if(true){
                ajaxFun('post','/pc/user/updateUserInfo',params,function(data){
                    if(data.code != 0){
                        alertFun(data);
                    }else{
                        window.location.href= path + "/modules/users/list.html";
                        console.log("success !");
                    }
                })
            }
              return false;
          });
        });
    </script></body></html>